package tuanvn.iti.vn;

import java.util.List;

import mrtran.iti.vn.Main;
import mrtran.iti.vn.Main.GameView;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class SpriteMonster5 {
	private GameView gameView5;
	private Bitmap bmpmonster5;
	private int widthMonster;
	private int heightMonster;
	private static final int BMP_COLUMNS_MONSTER = 7;
	private static final int BMP_ROWS_MONSTER = 2;
	public static int distance5;
	public static int monsterWidth5,widthLuffyMonster5;
	public static int xMonsterCenter5,yMonsterCenter5;
	private List<SpriteMonster5> spriteMonster5;
	
	int currentFrame5 = 0;
	public static int xSpeedMonster5 = 15;
	private static int ySpeedMonster5 = 0;
	int xMonster5=Main.SCREENWIDTH+Main.SCREENWIDTH+Main.SCREENWIDTH+Main.SCREENWIDTH,yMonster5 = Main.SCREENHEIGHT/2;
	int[] DIRECTION_TO_ANIMATION_MONSTER5 = {0,1};

	
	public SpriteMonster5(GameView gameView5, Bitmap bmpmonster5,List<SpriteMonster5> spriteMonster5) {
		this.gameView5 = gameView5;
		this.bmpmonster5 = bmpmonster5;
		this.distance5 = distance5;
		this.spriteMonster5 = spriteMonster5;
		this.widthMonster = bmpmonster5.getWidth() / BMP_COLUMNS_MONSTER;
		this.heightMonster = bmpmonster5.getHeight() / BMP_ROWS_MONSTER;
	}

	private void update() {	
		xMonster5-=xSpeedMonster5;
	    currentFrame5 = ++currentFrame5 % BMP_COLUMNS_MONSTER;	

			
			xMonsterCenter5= xMonster5+widthMonster/2;
			yMonsterCenter5 = yMonster5+heightMonster/2;
			monsterWidth5 = widthMonster/2;	   
			
			
			if (xMonster5 < gameView5.getWidth()/10-widthMonster-widthMonster-widthMonster) {						
					spriteMonster5.remove(this);		
					spriteMonster5.add(new SpriteMonster5(gameView5, bmpmonster5, spriteMonster5));
			}
		}

	public void onDraw(Canvas canvas) {
		update();
		int srcX5 = currentFrame5 * widthMonster;
		int srcY5 = getAnimationRowMonster5() * heightMonster;
		Rect src5 = new Rect(srcX5, srcY5, srcX5 + widthMonster, srcY5
				+ heightMonster);
		Rect dst5 = new Rect(xMonster5, yMonster5, xMonster5 + widthMonster,
				yMonster5 + heightMonster);
		canvas.drawBitmap(bmpmonster5, src5, dst5, null);
		
	}

	private int getAnimationRowMonster5() {
		double dirDouble = (Math.atan2(xSpeedMonster5, ySpeedMonster5)
				/ (Math.PI / 2) + 2);
		int direction = (int) Math.round(dirDouble) % BMP_ROWS_MONSTER;
		return DIRECTION_TO_ANIMATION_MONSTER5[direction];
	}

}
